package net
{
	import flash3.net.ByteArrayPlus;
	import flash3.net.MsgPacket;
	
	import model.*;
	
	import vo.*;
	public class ServerListGroup extends ManagerGroup
	{
		//游戏列表命令码
		
		public static const MDM_GP_SERVER_LIST:uint		=		102;									//列表信息
		
		public static const SUB_GP_LIST_TYPE:uint			=		100;								//类型列表
		public static const SUB_GP_LIST_KIND:uint			=		101;								//种类列表
		public static const SUB_GP_LIST_STATION:uint		=		102;								//站点列表
		public static const SUB_GP_LIST_SERVER:uint		=		103;								//房间列表
		public static const SUB_GP_LIST_FINISH:uint		=		104;								//发送完成
		public static const SUB_GP_LIST_CONFIG:uint		=		105;								//列表配置
		
		public static const SUB_GP_LIST_PROCESS:uint		=		106;								//进程列表
		public static const SUB_GP_LIST_PRIZEPOOL:uint	=		107;								//奖金池列表
		
		public function ServerListGroup()
		{
			super();
		}
		
		override public function defMessage():void
		{
			addMessage(new MessageDef(MDM_GP_SERVER_LIST, SUB_GP_LIST_TYPE, "类型列表", onListType));
			addMessage(new MessageDef(MDM_GP_SERVER_LIST, SUB_GP_LIST_KIND, "种类列表", onListKind));
			addMessage(new MessageDef(MDM_GP_SERVER_LIST, SUB_GP_LIST_STATION, "站点列表", onListStation));
			addMessage(new MessageDef(MDM_GP_SERVER_LIST, SUB_GP_LIST_SERVER, "房间列表", onListServer));
			addMessage(new MessageDef(MDM_GP_SERVER_LIST, SUB_GP_LIST_FINISH, "发送完成", onListFinish));
			addMessage(new MessageDef(MDM_GP_SERVER_LIST, SUB_GP_LIST_CONFIG, "列表配置", onListConfig));
			addMessage(new MessageDef(MDM_GP_SERVER_LIST, SUB_GP_LIST_PROCESS, "进程列表", onListProcess));
			addMessage(new MessageDef(MDM_GP_SERVER_LIST, SUB_GP_LIST_PRIZEPOOL, "奖金池列表", onListPrizePool));
		}
		public function onListType(packet:MsgPacket):void
		{
			var bap:ByteArrayPlus = packet._data;
			var listArr:Array = new Array;
			var listCnt:uint = bap.readShort();
			for(var i:uint=0;i<listCnt;i++)
			{
				var tgt:GameType = new GameType;
				tgt.wSortID = bap.readShort();
				tgt.wTypeID = bap.readShort();
				tgt.szTypeName = bap.readUTFBytes(32);
				listArr.push(tgt);
//				trace("GameType:","wSortID:",tgt.wSortID, "/", "wTypeID:",tgt.wTypeID, "/", "wKindID:",tgt.szTypeName);
			}
			
			
		}
		public function onListKind(packet:MsgPacket):void
		{
			var bap:ByteArrayPlus = packet._data;
			var listArr:Array = new Array;
			var listCnt:uint = bap.readShort();
			for(var i:uint=0;i<listCnt;i++)
			{
				var data:GameKind = new GameKind;
				data.wSortID = bap.readShort();
				data.wTypeID = bap.readShort();
				data.wKindID = bap.readShort();
				data.dwMaxVersion = bap.readUnsignedInt();
				data.dwOnLineCount = bap.readUnsignedInt();
				data.szKindName = bap.readUTFBytes(GameKind.KIND_LEN);
				data.szProcessName = bap.readUTFBytes(GameKind.MODULE_LEN);
				listArr.push(data);
//				trace("GameKind:","wSortID:",data.wSortID, "/", "wTypeID:",data.wTypeID, "/", "wKindID:",data.wKindID, "/", "dwMaxVersion:",data.dwMaxVersion, "/", "szKindName:",data.szKindName, "/", "szProcessName:",data.szProcessName);
			}
		}
		public function onListStation(packet:MsgPacket):void
		{
			
		}
		public function onListServer(packet:MsgPacket):void
		{
			var bap:ByteArrayPlus = packet._data;
			var listCnt:uint = bap.readShort();
			var gameServer:GameServer = null;
			for(var i:uint=0;i<listCnt;i++)
			{
				gameServer = new GameServer();
				gameServer.wSortID = bap.readShort();
				gameServer.wKindID = bap.readShort();
				gameServer.wServerID = bap.readShort();
				gameServer.wStationID = bap.readShort();
				gameServer.wServerPort = bap.readShort() & 0xffff;
//				gameServer.dwServerAddr = bap.readUnsignedInt();
				gameServer.dwOnLineCount = bap.readUnsignedInt();
				gameServer.dwCellMoney = bap.readUnsignedInt();
				gameServer.dwServerType = bap.readUnsignedInt();
				gameServer.dwEnterFee = bap.readUnsignedInt();
				gameServer.szServerName = bap.readUTFBytes(GameServer.SERVER_LEN);
				if(gameServer.wKindID == 102)
					GameServerModel.i.add(gameServer);
//				trace("GameServer:","wSortID:",gameServer.wSortID, "/", "wKindID:",gameServer.wKindID, "/", "wServerID:",gameServer.wServerID, "/", "wStationID:",gameServer.wStationID, "/", "wServerPort:",gameServer.wServerPort, "/", "dwServerAddr:",gameServer.dwServerAddr,"/","dwOnLineCount:",gameServer.dwOnLineCount, "/", "dwServerType:", gameServer.dwServerType, "/", "szServerName:",gameServer.szServerName);
			}
			GameServerModel.i.values().sortOn("wServerID", Array.NUMERIC);
			gameServer = GameServerModel.i.value(0);
		}
		public function onListFinish(packet:MsgPacket):void
		{
			
		}
		public function onListConfig(packet:MsgPacket):void
		{
			var bap:ByteArrayPlus = packet._data;
			var count:uint = bap.readByte();
			GlobalModel.i.bShowOnLineCount = count;
		}
		public function onListProcess(packet:MsgPacket):void
		{
			
		}
		public function onListPrizePool(packet:MsgPacket):void
		{
			var bap:ByteArrayPlus = packet._data;
			var count:uint = bap.readShort();
			for(var i:uint = 0; i < count; i++)
			{
				var poolItem:MoneyPoolItem = new MoneyPoolItem();
				poolItem.read(bap);
				PrizePoolModel.i.add(poolItem.wServerID, poolItem);
			}
		}
	}
}